package etcdx

import "C"
import (
	"fmt"
	"time"

	"nosqlx/config"

	clientv3 "go.etcd.io/etcd/client/v3"
)

func EtcdClient() *clientv3.Client {
	client, err := clientv3.New(clientv3.Config{
		Endpoints:           config.EtcdEndpoints, // Etcd 服务器地址
		DialTimeout:         3 * time.Second,
		Username:            config.EtcdUserName,
		Password:            config.EtcdPassword,
		RejectOldCluster:    false,
		PermitWithoutStream: false,
	})
	if err != nil {
		panic(err)
	}
	get, err := client.Get(config.Ctx, "", clientv3.WithPrefix())
	if err != nil {
		panic(err)
	}
	fmt.Println(get.Count)
	return client
}
